<template>
  <div>
    <el-row type="flex" justify="end">
      <el-select v-model="currentYear" size="small" style="margin-right: 10px; width: 120px" @change="changeFn">
        <!-- 年份取给定年份的，前五年 + 后五年 -->
        <el-option v-for="item in yearList" :key="item" :label="item" :value="item" />
      </el-select>
      <el-select v-model="currentMonth" size="small" style="width: 120px" @change="changeFn">
        <el-option v-for="item in 12" :key="item" :label="item" :value="item" />
      </el-select>
    </el-row>
    <el-calendar v-model="current">
      <template #dateCell="{date, data}">
        <div class="date-content">
          <span class="text" :class="{current: data.isSelected}"> {{ date.getDate() }} </span>
          <span v-if="showDate(date)" class="rest">休</span>
        </div>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  name: 'WorkCalendar',
  data() {
    return {
      currentYear: new Date().getFullYear(),
      currentMonth: new Date().getMonth() + 1,
      current: new Date()
    }
  },
  computed: {
    yearList() {
      const list = []
      for (let i = this.currentYear - 5; i < this.currentYear + 5; i++) {
        list.push(i)
      }
      return list
    }
  },
  watch: {
    current: {
      deep: true,
      handler(value) {
        this.currentYear = value.getFullYear()
        this.currentMonth = value.getMonth() + 1
      }
    }
  },
  methods: {
    changeFn() {
      this.current = new Date(this.currentYear, this.currentMonth - 1)
    },
    showDate(date) {
      // console.log(date.getDay())
      return date.getDay() === 0 || date.getDay() === 6
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep{
  .el-calendar__header{
    display: none;
  }
}
::v-deep .el-calendar-day {
  height:  auto;
 }
.date-content {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text{
  width: 20px;
  height: 20px;
  line-height: 20px;
 display: inline-block;

}
.current{
   background: #409eff;
   color: #fff;
   border-radius: 50%;
 }
</style>
